<template>
  <div>
    <Spin :spinning="loading" tip="Loading...">
      <div style="padding-top: 1rem;"></div>
      <!-- table -->
      <FormPanel ref="formPanel" :list="formList" :cols="1" :formType="'add'" labelWidth="110" :isSubmitBtn="false" @formChange="formChangeHandle" />
      <div style="padding-top: 1rem;"></div>
      <div
        :style="{
          position: 'absolute',
          left: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <multiuse-button type="primary" :click="saveDialog.bind()">保 存</multiuse-button>
        <multiuse-button @click="closeDialog">关 闭</multiuse-button>
      </div>

    </Spin>
  </div>
</template>
<script>
import { selectById, editSave } from '@/api/claim/factory/AuthLabour';
import { getAppId} from '@/assets/js/auth';
import {dictionary} from'@/utils/dictMixin';
export default {
  mixins: [dictionary],
 components: {

  },
  props: ['type', 'rowData'],
  data() {
    return {
      loading: false,
      dataList1: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      infoId: null,
      flterValue: {}, //参数
      fetchParams: {}, //ipa 接口
      selectedRows: [], //选中经销商
      formList: this.createFormList1(),
      saveData: null,
      activeName: '审核记录',
      newVar: {}
    };
  },
  created() {
   // this.chuqi()
    if(getAppId()=='beijing'){
      this.formList.find((x) => x.fieldName == 'powerType').itemList = this.createDictList('6008');
    }else{
      this.formList.find((x) => x.fieldName == 'powerType').itemList = this.createDictList('6008');
      this.formList.find((x) => x.fieldName == 'powerType').initialValue = 60081002;
      this.formList.find((x) => x.fieldName == 'powerType').disabled=true;
    }
  },
  mounted() {
    this.init();
  },
  methods: {
    formChangeHandle(val) {
      console.log(val);
      this.saveData = val;
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = val;
      console.log(val);
    },
    async init() {
      this.loading = true;
      let newVar = await selectById({id: this.rowData.alId});
      this.formList.forEach(x => {
        console.log(this.rowData);
        x.initialValue = newVar.data[x.fieldName];
      });
      this.newVar = newVar.data;
      this.loading = false;
    },
    async chuqi() {

    },
    //保存
    async saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
      if (this.saveData !== null) {
        console.log(this.saveData);
       // this.saveData.typeId = this.rowData.typeId;
        this.saveData.alId = this.rowData.alId;
        this.saveData.isDeleted = this.rowData.isDeleted;
        // this.saveData.createdBy = this.rowData.createdBy;
        // this.saveData.createdAt = this.rowData.createdAt;
        this.saveData.updatedAt = null;
        this.saveData.updatedBy = null;
        for (let key in this.saveData) {
          this.newVar[key] = this.saveData[key];
        }
        this.loading = true;
        let res = await editSave(this.newVar);
        console.log(res);
        if (res.resultCode === 200) {
          this.$emit('save');
          return this.$notify.success({ title: '提示信息', message: '保存成功' });
        } else {
          this.loading = false;
          // this.$notify.error({ title: '提示信息', message: res.errMsg || '保存失败!' });
          // this.closeDialog();
        }
      }
    },
    //取消操作
    closeDialog() {
      this.$emit('close');
    },
    add() {},

    save(obj) {
      console.log(obj);
      this.formList.find(x => x.fieldName == 'labourCode').initialValue = obj[0].labourCode;
      this.formList.find(x => x.fieldName == 'labourName').initialValue = obj[0].labourName;
      this.formList.find(x => x.fieldName == 'powerType').initialValue = obj[0].powerType;
      this.visible = false;
    },
    close() {
      this.visible = false;
    },
    createFormList1() {
      return [
        {
          type: 'INPUT',
          label: '工时代码',
          fieldName: 'labourCode',
          placeholder: '请选择工时代码...',
          readonly: false,// 只读
          rules: [{ required: true, message: '请选择工时代码...', trigger: 'blur' }],
        },
        {
          type: 'INPUT',
          label: '工时名称',
          fieldName: 'labourName',
          readonly: false,// 只读
          disabled: false,// 置会
          rules: [{ required: true, message: '请输入工时名称', trigger: 'blur' }],
          placeholder: '请输入工时名称...'
        },
        {
          type: 'SELECT',
          label: '动力形式',
          fieldName: 'powerType',
          placeholder: '请选择动力形式...',
          initialValue: '',
          itemList: this.createDictList('6008'),
          filterable:true,
          rules: [{required: true, message: '请选择动力形式...', trigger: 'change'}]
        },

      ];
    }
  }
};
</script>

<style lang="less" scoped></style>
